$(function(){
    twoLevelmenu();
    initContent();
    fixTop();
    backTop();
})
//初始化部分内容
function initContent(){
  
    var smallBannerpic = function(){
    
        var BannerSmallimgArr = [
            {
                img:"small1.jpg"
            },
            {
                img:"small2.jpg"
            },
            {
                img:"small3.jpg"
            },
            {
                img:"small4.jpg"
            },{
                img:"small5.jpg"
            }]
    
            BannerSmallimgArr.forEach(function (item){
                $(".small").append(`<img src = "img/${item.img}">`)
                $(".small").children().first().addClass("active")
            })
    }
    var initMainConent = function(){
       for(let i = 0;i<4 ;i++){ 
        createMainContent();
    }
    }

    smallBannerpic();
    initMainConent();
}
//初始化block
function createMainContent(){
        $(".content-container").prepend(`<div class ="row"></div>`);
        $(".row").eq(0).append(blockcontent()); //为首个row赋值 下标会自动偏移
        function blockcontent()
        {
            var str = ""
            var blockstr = `<div class="block">
                                <img src="img/block.jpg" alt="">
                                <div class = "infocard">
                                <p class="head_p">呆萌的阿猪第二弹</p>
                                <p class="context_p">动漫-网络表情</p>
                                    <div class="icon">
                                        <span class="iconfont icon-eye">&nbsp;233</span><span class="iconfont icon-pinglun">&nbsp;424</span><span class="iconfont icon-dianzan">&nbsp;244</span>
                                    </div>
                                </div>
                                <div class = "block_userinfo">
                                    <div class = "block_userinfo_left">
                                        <img class="touxiang" src="img/touxiang.jpg"><span class="user">Admin</span>
                                    </div>
                                    <p class="time">12小时以前</span>
                                </div>
                            </div>`
                            for(let i = 0; i<=4 ; i++)
                            {
                                str += blockstr;
                            }
                            return str;
        }
}
//二级菜单
function twoLevelmenu(){
    var index = $(this).index(); 
    //鼠标经过

    $("#nav > li").mouseover(function(){

        $(this).eq(index).addClass("active").siblings().removeClass("active");

        $(this).children("ul").show();

        
        $(this).children().children().hover(function(){
            $(this).addClass("active");
        },function(){
            
            $(this).removeClass("active");
        });

        $(this).children().children().children().hover(function(){
            $(this).addClass("active");
        },function(){
            $(this).removeClass("active");
        });
    });

    $("#nav > li").mouseout(function(){
        $(this).children("ul").hide();
        $(this).eq(index).removeClass("active");

    })

}

//固定栏
function fixTop (){

    $(window).scroll(function(){

        var top = $(this).scrollTop();

        console.log(top);

        if(top>670)
        {
            $(".title").addClass("fixed");
          
        }else{

            $(".title").removeClass("fixed");

        }
    })
}
//返回顶部
function backTop(){
    // $("#back_top").hide();
    $("#back_top").click(function(){
        // $("body,html").scrollTop(0);
        $("body,html").animate({scrollTop:0},300);
    })
    $("html")
}